import 'package:flutter/material.dart';

main() {
  runApp(TextView());
}

class TextView extends StatefulWidget {
  const TextView({Key? key}) : super(key: key);

  @override
  _TextViewState createState() => _TextViewState();
}

class _TextViewState extends State<TextView> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: TextHome(),
      ),
    );
  }
}

class TextHome extends StatefulWidget {
  TextHome({Key? key}) : super(key: key);


  @override
  _TextHomeState createState() => _TextHomeState();
}

class _TextHomeState extends State<TextHome> {

  String _username = "";
  String _password = "";

  var _textControl = new TextEditingController();

  @override
  void initState() {
    // TODO: implement initState

    _textControl.text = "默认值";

  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: [
          SizedBox(
            height: 40,
          ),
          Container(
            child: TextField(
              decoration: InputDecoration(hintText: '请输入意见和建议'),
              maxLines: 5,
            ),
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            margin: EdgeInsets.all(10),
            child: TextField(
              obscureText: true,
              decoration: InputDecoration(
                  hintText: "请输入密码",
                  // border: OutlineInputBorder(
                  //     borderSide: BorderSide(color: Colors.red, width: 1)),
                  focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.red, width: 1)),
                  enabledBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.black, width: 1))),
            ),
          ),
          SizedBox(
            height: 10,
          ),
          Container(
              width: 1200,
              height: 60,
              margin: EdgeInsets.all(20),
              child: TextField(
                decoration: InputDecoration(
                    hintText: "宽度",
                    focusedBorder: OutlineInputBorder(
                        borderSide: BorderSide(width: 1, color: Colors.yellow)),
                    enabledBorder: OutlineInputBorder(
                        borderSide: BorderSide(color: Colors.black, width: 1))),
              )),
          Container(
            height: 50,
            child: TextField(
              decoration: InputDecoration(
                  labelText: '用户名',
                  focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.blue, width: 1)),
                  enabledBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.black, width: 1)),
                  border: OutlineInputBorder(
                    borderSide: BorderSide(color: Colors.blue, width: 1),
                  )),
              onChanged: (value) {
                _username = value;
                _textControl.text = value;
              },
              controller: _textControl,

            ),
            margin: EdgeInsets.only(left: 20, right: 20),
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            margin: EdgeInsets.only(left: 20, right: 20),
            height: 50,
            child: TextField(
              maxLines: 1,
              obscureText: true,
              decoration: InputDecoration(
                  labelText: '密码',
                  focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.red, width: 1)),
                  enabledBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.grey, width: 1))),
              onChanged: (value) {
                _password = value;
              },
            ),
          ),
          SizedBox(
            height: 5,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [ElevatedButton(onPressed: () {
              print('用户名${_username}, 密码${_password}');
              print('control获取的值${_textControl.text}');
                  }, child: Text('登录'))],
          )
        ],
      ),
    );
  }
}
